<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 
功能介绍：模版信息

 -->
<%@ include file="/files/db/conn.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.tabfont01 {	
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}
.font051 {font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}
.font201 {font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}
html { overflow-x: auto; overflow-y: auto; border:0;} 
-->
</style>
<%
if(request.getParameter("flag")!=null&&"success".equals(request.getParameter("flag"))){
	response.getWriter().println("<script>alert('操作成功!');</script>");
}
%>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javaScript">
		function openPage(curpage)
		{
			document.forms[0].cp.value = curpage ;
			document.forms[0].submit() ;
		}
</script>
        <%
        

        int count = 0;//记录数
		// 进行乱码处理
		request.setCharacterEncoding("GB2312"); 
		// 定义如下分页变量
		// 1、定义没页要显示的记录数
		int lineSize = 5;
		// 2、定义一个当前是第几页
		int currentPage = 1;
		// 计算出总页数
		int pageSize = 0;
		// 总记录数 / 每页显示的记录数
		int allRecorders = 30;
		// 加入查询关键字变量
		// 接收查询关键字
		String keyWord1 = null;
		keyWord1 = request.getParameter("fname");
             if(keyWord1==null){
             	keyWord1="";
        		 }else{
                 try{
                 	//String(byte[] bytes, Charset charset)
                 	//通过使用指定的 charset 解码指定的 byte 数组，构造一个新的 String
                 	System.out.println(keyWord1);
                        // keyWord1=(new String(keyWord1.getBytes("iso-8859-1"),"UTF-8")).trim();
                      	System.out.println(keyWord1);
                 }catch(Exception e){
                         e.printStackTrace(System.err);
                 }
        		 }
		// 接收传过来的当前页
		try {
			currentPage = Integer.parseInt(request.getParameter("cp"));
		} catch (Exception e) {
		}
		try {
			
			PreparedStatement pstmt = null; 
			String sql = null;
			if (keyWord1 == null||"".equals(keyWord1)) {
				// 如果为空则没有查询，表示查询出全部
				sql = "select count(*) from t_file f ,t_filetype t where f.typeid = t.id and ( f.fromuser = '"+(String)session.getAttribute("id")+"'  or f.touser = '"+(String)session.getAttribute("id")+"' ) ";
			} else {
				//如果KeyWord有值 则执行模糊查询
				sql = "select count(*) from t_file f ,t_filetype t where f.typeid = t.id  and ( f.fromuser = '"+(String)session.getAttribute("id")+"'  or f.touser = '"+(String)session.getAttribute("id")+"' )  and f.title like '%"+keyWord1+"%'";
			}
			System.out.println(sql);
			pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next()) {
				allRecorders = rs.getInt(1);
			}
			rs.close();
			pstmt.close();

			// 计算总页数
			pageSize = (allRecorders + lineSize - 1) / lineSize;
			if (keyWord1 == null||"".equals(keyWord1)) {
				// 如果为空则没有查询，表示查询出全部
				sql = "select f.title,f.remark,f.inputdate,f.status,f.typeid,u1.realname as u1,u2.realname as u2,t.typename,f.url  from t_file f ,t_filetype t,t_user u1,t_user u2 where u1.id = f.fromuser and u2.id = f.touser  and f.typeid = t.id and ( f.fromuser = '"+(String)session.getAttribute("id")+"'  or f.touser = '"+(String)session.getAttribute("id")+"' )  ";
			} else {
				//如果KeyWord有值 则执行模糊查询
				sql = "select f.title,f.remark,f.inputdate,f.status,f.typeid,u1.realname as u1,u2.realname as u2,t.typename,f.url  from t_file f ,t_filetype t,t_user u1,t_user u2 where u1.id = f.fromuser and u2.id = f.touser  and f.typeid = t.id and ( f.fromuser = '"+(String)session.getAttribute("id")+"'  or f.touser = '"+(String)session.getAttribute("id")+"' )  and f.title like '%"+keyWord1+"%'";
			}	
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			
	%> 
</head>
<body>
<form name="fom" id="fom" method="post" action="files/file/alllist.jsp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="62" background="images/nav04.gif">
          
		   <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
		  <tr>
		
			<td width="550">查看内容： 按标题：
              <input type="text" name="fname" value="<%=keyWord1==null?"":keyWord1%>" />
              <input name="Submit" type="submit" class="right-button02" value="查 询" /></td>
			 <td width="132" align="left"></td>	
		  </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table id="subtree1" style="DISPLAY: " width="100%" border="0" cellspacing="0" cellpadding="0">

        <tr>
          <td><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">

          	 <tr>
               <td height="20"><font color="blue"  >统计文件</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a onclick="javascript:window.print();" href="javascript:void(0);" >打印</a> </td>
          	 </tr>
          	 <tr>
               <td height="10" valign="top" ><hr size="1" color="green" /></td>
          	 </tr>
              <tr>
                <td height="40" class="font42">
                <table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#464646" >
                
                  <tr>
                    <td  align="center" bgcolor="#EEEEEE">序列</td>
				    <td  align="center" bgcolor="#EEEEEE">标题</td>
				    <td  align="center" bgcolor="#EEEEEE">备注</td>
				    <td  align="center" bgcolor="#EEEEEE">发送时间</td>
				    <td  align="center" bgcolor="#EEEEEE">发送人</td>
				    <td  align="center" bgcolor="#EEEEEE">接收人</td>
				    <td  align="center" bgcolor="#EEEEEE">文件类型</td>
				    <td  align="center" bgcolor="#EEEEEE">状态</td>
					<td  align="center" bgcolor="#EEEEEE">操作</td>
                  </tr>
					<%
					if (allRecorders > 0) {
						
						int i = 0;
						for (int x = 0; x < (currentPage - 1) * lineSize; x++) {
							rs.next();
						}
						// 对于输出代码之前要求按显示的页数空出
						for (int x = 0; x < lineSize; x++) {
							if (rs.next()) {
								i++;		
					%> 					
	                  <tr>
	                    <td bgcolor="#FFFFFF"  height="20" align="center" ><%=i %></td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("title")%></td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("remark")%></td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("inputdate")%></td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("u1")%></td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("u2")%></td>
					    <td bgcolor="#FFFFFF"  align="center">
					    <%if("0".equals(rs.getString("status"))){  %>未签收<%} %>
					    <%if("1".equals(rs.getString("status"))){  %>已签收<%} %>
					    <%if("2".equals(rs.getString("status"))){  %>已退回<%} %>
					    </td>
					    <td bgcolor="#FFFFFF"  align="center"><%=rs.getString("typename")%></td>
					    <td bgcolor="#FFFFFF"  align="center">
					    <a href="/fileweb/upload/<%=rs.getString("url")%>" >下载</a>
 						</td>
	                  </tr>
              <%
						}
					}
						}
					%>
                </table></td>
              </tr>
              <tr>
              	<td>
              	   <%
					if (allRecorders > 0) {
					%>
                <center><br>
				<font size="2">
					<input type="button" value="首页" onClick="openPage(1)"
						<%=currentPage == 1 ? "disabled" : ""%>>
					<input type="button" value="上一页"
						onClick="openPage(<%=currentPage - 1%>)"
						<%=currentPage == 1 ? "disabled" : ""%>>
					<input type="button" value="下一页"
						onClick="openPage(<%=currentPage + 1%>)"
						<%=currentPage == pageSize ? "disabled" : ""%>>
					<input type="button" value="尾页" onClick="openPage(<%=pageSize%>)"
						<%=currentPage == pageSize ? "disabled" : ""%>>
					<input type="hidden" name="cp" value=""> 
					</font>
			   </center>
			     <%}%>
              	</td>
              </tr>              
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</form>
</body>
</html>
<%
} catch (Exception e) {
	out.println(e.getMessage());
} finally {
	if (stmt != null) {
		try {
			stmt.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	if (conn != null) {
		try {
	conn.close();
		} catch (Exception e) {
	e.printStackTrace();
		}
	}
}
%>